package com.xujie.property_warranty_system.controller;

import com.xujie.property_warranty_system.common.Result;
import com.xujie.property_warranty_system.entity.Role;
import com.xujie.property_warranty_system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色控制器
 */
@RestController
@RequestMapping("/api/roles")
@CrossOrigin(origins = "*")
public class RoleController {
    
    @Autowired
    private RoleService roleService;
    
    /**
     * 获取所有角色列表
     */
    @GetMapping
    public Result<List<Role>> getAllRoles() {
        try {
            List<Role> roles = roleService.list();
            return Result.success(roles);
        } catch (Exception e) {
            return Result.error("获取角色列表失败：" + e.getMessage());
        }
    }
}
